<template>
  <ve-line
    :colors="colors"
    :data="chartData"
    :data-empty="dataEmpty"
    :extend="extendsConfig"
    :legend-visible="false"
    :loading="loading"
    :settings="chartSettings"
    height="342px"
  />
</template>

<script>
import VeLine from 'v-charts/lib/line.common';
import 'v-charts/lib/style.css';

export default {
  components: {
    VeLine
  },
  data() {
    return {
      loading: true,
      dataEmpty: false,
      chartSettings: {
        labelMap: {
          date: '日期',
          sale_price: '销售额'
        },
        yAxisName: ['销售额/' + this.site.money_title]
      },
      extendsConfig: {
        series: {
          smooth: false
        },
        xAxis(v) {
          v.forEach(i => {
            i.boundaryGap = false;
            i.axisLabel = {
              showMaxLabel: true,
              rotate: 45
            };
          });

          return v;
        }
      },
      colors: ['#5191FF'],
      chartData: {
        columns: ['date', 'sale_price'],
        rows: []
      }
    };
  },
  created() {
    this.loadData();
  },
  methods: {
    loadData: function () {
      this.$http.get(
          '/admin/data/survey/today/sale/price',
          {
            time: 'today'
          },
          response => {
            const data = response.data.rows;
            if (data.length == 0) {
              this.dataEmpty = true;
              this.chartData.rows = [];
            } else {
              this.dataEmpty = false;
              this.chartData.rows = data;
            }

            this.loading = false;
          },
          _ => {
            this.loading = false;
          },
          false
      );
    }
  }
};
</script>

<style></style>
